package utils

import (
	"crypto/md5"
	"encoding/hex"
	"strings"
)

func NewMd5String(s string, sign string) string {
	h := md5.New()
	h.Write([]byte(toLower(s) + sign))
	tempStr := h.Sum(nil)
	return hex.EncodeToString(tempStr)
}

func ValidateMd5(str string, sign string, compareStr string) bool {
	return NewMd5String(str, sign) == compareStr
}

func toLower(s string) string {
	return strings.ToLower(s)
}
